<?php

namespace app\models;

use think\Model;

/**
 * Class CampusPriceConfigureModel.
 */
class CampusPriceConfigureModel extends Model
{
    protected $table = 'edu_campus_price_configure';

    /**
     * 获取校区合计
     *
     * @param $id
     *
     * @throws \think\Exception
     *
     * @return array|int|string
     */
    public static function getByIdCampusNum($id)
    {
        if (!is_numeric($id)) {
            return [];
        }
        $course = self::where('course_id', $id)->select();
        return count($course);
    }

    /**
     * @param $id
     * @param $course_id
     * @param string $type
     *
     * @throws \think\exception\DbException
     *
     * @return null|array|CampusPriceConfigureModel
     */
    public static function getById($id, $course_id, $type = 'all')
    {
        if (!is_numeric($id) && !is_numeric($course_id)) {
            return [];
        }
        $campus_price_configure = self::get(['campus_id' => $id, 'course_id' => $course_id]);
        if ($campus_price_configure) {
            return (isset($campus_price_configure[$type])) ? $campus_price_configure[$type] : $campus_price_configure;
        }

        return [];
    }

    /**
     * 获取人事列表.
     *
     * @param $param
     *
     * @throws \think\Exception
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getAuthorizationLists($param)
    {
        $page = isset($param['page']) ? (int) $param['page'] : 1;
        $listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
        $where = [];
        if (isset($param['station_name']) && '' !== $param['station_name']) {
            $where['station_name'] = ['like', $param['station_name'].'%'];
        }
        if (isset($param['id']) && '' !== $param['id']) {
            $where['course_id'] = $param['id'];
        }

        $listData = $this->where($where)
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
//                $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
//                $item['sex'] = (0 === $item['sex']) ? '男' : '女';
//                $item['staff_status'] = (0 === $item['staff_status']) ? '在职' : '离职';
//                $item['department'] = DepartmentModel::getDepartmentByStationId($item['station_id'], 'department_name');
//                $item['station'] = StationModel::getStationById($item['station_id'], 'station_name');
//                $item['division'] = WordBookDetailModel::getById($item['division'], 'data_value');
//                $staff_id = BusinessUserModel::getByUserId($item['user_id'], 'staff_id');

//                $item['campus_num'] = self::where(['staff_id' => $staff_id])->value('staff_name');
            }
        }

        return $listData;
    }
}
